// pages/home/search/search.js
Page({
  data: {
    'ext-class': 'searchBar',
    placeholder:'输入检索词',
    cancel:'false', 
    serviceType:'policy',
    active: '0',
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },

  changeService: function (e) {
    const type=e.currentTarget.dataset.type;
    const index=e.currentTarget.id;
    this.setData({serviceType:type,active:index})
  },

  onSearch: function (e) {
    const that=this
    let serviceType=this.data.serviceType
    let p=''
    if(serviceType=="policy"){
      p='home3'
    }else if(serviceType=="users"){
      p='home1'
    }else if(serviceType=="discharge"){
      p='home2'
    }
    const detail=e.detail
    wx.navigateTo({
      url: './search-result/search-result',
      events: {
        // 为指定事件添加一个监听器，获取被打开页面传送到当前页面的数据
        acceptDataFromOpenedPage: function(data) {
          console.log(data)
        },
        someEvent: function(data) {
          // console.log(data)
        }
      },
      success: function(response) {
        // 通过 eventChannel 向被打开页面传送数据
        response.eventChannel.emit('acceptDataFromOpenerPage', {page:p,context:detail})
      }
    })
  },

  onChange: function(e) {

  }
})